﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Reporting.WinForms;

namespace InSys.Documents
{
    public partial class FormReportDocumentCountByPerson : Form
    {
        private string kindDocument;
        private string userName;
        private AccessUserLoginInfo userInfo;
        private int id_user;

        public FormReportDocumentCountByPerson()
        {
            InitializeComponent();
            kindDocument = "";
            userName = "";
            id_user = -1;
            userInfo = new AccessUserLoginInfo();
        }

        public FormReportDocumentCountByPerson(int idUser)
            : this()
        {
            id_user = idUser;
        }

        private void FormReportDocumentCountByPerson_Load(object sender, EventArgs e)
        {
            MapTestLinqDataContext db = new MapTestLinqDataContext();
            db.ObjectTrackingEnabled = false;
            kindDocument = (from item in db.kindDocument where item.id == Program.gKindDocument select item.kind_document).FirstOrDefault();
            labelKindDoc.Text = string.Format("Вид документа: {0}", kindDocument);
            userName = userInfo.GetUserNameById(id_user);
            this.reportViewer1.RefreshReport();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            DataTableCountTotalDocumentByDateTableAdapter.Fill(testlinqDataSet.DataTableCountTotalDocumentByDate, Program.gKindDocument, dateTimePicker1.Value);
            ReportParameter rpKindDocument = new ReportParameter("ReportParameterKindDocument", kindDocument);
            ReportParameter rpUserName = new ReportParameter("ReportParameterUser", userName);
            ReportParameter rpDate = new ReportParameter("ReportParameterDate", dateTimePicker1.Value.ToString());
            reportViewer1.LocalReport.SetParameters(new ReportParameter[] { rpKindDocument, rpUserName, rpDate });
            reportViewer1.RefreshReport();
        }
    }
}
